#!/usr/bin/env bash

cd /opt/spring-learn

# 压缩生成的非jar包形式，如果打jar包，不需要这个
# tar -cf demo.tar.gz bin conf lib

# stop the docker container
docker ps -a -f name="spring-learn" | awk 'NR ==2 {print $1}' | xargs docker stop

# docker rm 删除docker container
# docker rmi 删除docker images
# container是镜像的一次运行
docker rmi -f spring-learn:1.0
id=$(docker ps -a -f name="spring-learn" | awk 'NR == 2 {print $1}')
echo "Delete instance:"$id
docker rm $id

echo "Start building..."
docker build -t spring-learn:1.0 /opt/spring-learn

echo "Checking..."
docker images | grep spring-learn

echo "Running..."
docker run -d --name="spring-learn" -p 8000:8000 spring-learn:1.0 
